const router = require('koa-router')();
const files = require('../app/controller/files');
const serverUtil = require('../utils/serverUtil');

router.post('/upload', async function (ctx, next) {

    try {
        let tmp_file = ctx.request.body.files.file;
        // const loc_path = ctx.request.body.fields.localUrl || '';
        let uid = serverUtil.getLoginUid(ctx);
        let result = await files.upload(uid, tmp_file);
        ctx.body = {
            code: serverUtil.code.SUCCESS,
            data: result
        }
    } catch (e) {
        let code = e.code || serverUtil.code.UNKNOWN;
        ctx.body = {
            code: code
        }
        serverUtil.logError(ctx, e, "login failed");
    }
});


module.exports = router;